home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 283_03 / printer.c < prev    next >
C/C++ Source or Header  |  1988-12-01  |  5KB  |  169 lines

  1.  
  2. /* printer.c -- for burlap, 11/29/88, d.c.oshel */
  3.  
  4. #include "burlap.h"
  5.  
  6. extern FORM_RULES burlap[];
  7. extern char vrec[ BUFSIZE ];
  8.  
  9. #define LABELWIDTH 3    /* mailing labels are 3.5'' wide by 15/16'' deep */ 
  10.  
  11. #define PICA 0
  12. #define ELITE 1
  13. #define CMPRX 2
  14.  
  15. static int pfofs[] = { 78, 102, 131 }; /* offsets into patch area */
  16. static char printfont[] = {
  17.  
  18.       '[', 'P', 'r', 'i', 'n', 't', 'e', 'r', ' ', 'P',
  19.       'a', 't', 'c', 'h', ' ', 'A', 'r', 'e', 'a', ' ',
  20.  
  21.       '(', 'S', 't', 'a', 'y', ' ', 'w', 'i', 't', 'h',
  22.       'i', 'n', ' ', 'b', 'r', 'a', 'c', 'k', 'e', 't',
  23.  
  24.       's', ',', ' ', 'f', 'i', 'r', 's', 't', ' ', 'b',
  25.       'y', 't', 'e', ' ', '=', ' ', 'l', 'e', 'n', 'g',
  26.  
  27.       't', 'h', ' ', 'o', 'f', ' ', 's', 't', 'r', 'i',
  28.       'n', 'g', ':', 'P', 'i', 'c', 'a', '{', 
  29.  
  30.             7, '\x1b', 'U', '0', '\x1b', 'P', '\x1b', 'n',
  31.             0xff, 0xff, 0xff, 0xff,   0xff, 0xff, 0xff, 0xff,
  32.             '}',
  33.  
  34.       ':', 'E', 'l', 'i', 't', 'e', '{',
  35.  
  36.             7, '\x1b', 'U', '1', '\x1b', 'P', '\x1b', 'M',
  37.             0xff, 0xff, 0xff, 0xff,   0xff, 0xff, 0xff, 0xff,
  38.             '}',
  39.  
  40.       ':', 'C', 'o', 'm', 'p', 'r', 'e', 's', 's', 'e', 'd', '{',
  41.  
  42.             6, '\x1b', 'U', '1', '\x1b', 'P', '\x0f', 0xff, 0xff,
  43.             0xff, 0xff, 0xff, 0xff,   0xff, 0xff, 0xff, 0xff,
  44.             '}',
  45.  
  46.       ':', 'E', 'n', 'd', ' ', 'P', 'a', 't', 'c', 'h', ' ', 
  47.       'A', 'r', 'e', 'a', ']'
  48.       };
  49.  
  50. #define fontcmd(F) (&printfont[pfofs[F]])
  51.  
  52.  
  53.  
  54. static int limit;
  55.  
  56. static void prt_label_line( char *pline )
  57. {
  58.       char *p, *prntrcmd;
  59.       int cnt, doublestrike;
  60.  
  61.       /* adjust label line width to actual length of data received;
  62.       ** data too long is TRUNCATED on the label
  63.       */
  64.  
  65.       doublestrike = 0;
  66.       limit = 80;
  67.  
  68.       if ( strlen(pline) <= 10 * LABELWIDTH )
  69.       {
  70.           prntrcmd = fontcmd( PICA );
  71.           limit = 10 * LABELWIDTH;
  72.       }
  73.       else if ( strlen(pline) <= 12 * LABELWIDTH )
  74.       {
  75.           prntrcmd = fontcmd( ELITE );
  76.           limit = 12 * LABELWIDTH;
  77.           doublestrike = 1;
  78.       }
  79.       else /* long line, default to compressed print */
  80.       {
  81.           prntrcmd = fontcmd( CMPRX );
  82.           limit = 17 * LABELWIDTH;
  83.           doublestrike = 1;
  84.       }
  85.  
  86.       /* Uses WordStar style; i.e., first byte is length of cmd string, 
  87.       ** to allow zero byte to be sent to printer.
  88.       */
  89.  
  90.       for ( cnt = ((*prntrcmd++) & 0xff); cnt > 0; cnt--, prntrcmd++ )
  91.           fputc( *prntrcmd, stdprn );
  92.  
  93.  
  94.       /* send up to limit chars from p to file or stdprn
  95.       */
  96.  
  97. dbl:  for ( p = pline, cnt = 0; isprint(*p) && cnt < limit; p++, cnt++ )
  98.       {
  99.             fputc( *p, stdprn );
  100.       }
  101.       /* doublestrike underemphasized printer fonts */
  102.       if ( doublestrike )
  103.       {
  104.             fputc( '\r', stdprn );
  105.             doublestrike = 0;
  106.             goto dbl;
  107.       }
  108.  
  109.       fputc( '\r', stdprn);
  110.       fputc( '\n', stdprn);
  111.       fflush( stdprn );
  112. }
  113.  
  114.  
  115.  
  116.  
  117. void print_labels( int index )  /* index determines sort order */
  118. {
  119.     int i,j,n;
  120.     char *q;
  121.  
  122.     if ( choose_records() )
  123.     {
  124.         if ( ask("Printer ready?") ) {
  125.         fullscreen();
  126.         put_screen();
  127.         gotoxy( 2,0 );
  128.         wputs( "╡^2 Print Labels ^0╞" );
  129.         gotoxy( 62,18 );
  130.         wputs( "^1Esc^0 halts!" );
  131.         for ( n = FRSREC( index,vrec ); n != 101 ; n = NXTREC( index,vrec ))
  132.         {
  133.             if ( n )
  134.                 ISAM_crash( "NXTREC" );
  135.  
  136.             if ( kbhit() && getch() == ESC )
  137.                 break;
  138.  
  139.             if ( REDVREC( datno, vrec, BUFSIZE ) )
  140.                 ISAM_crash("REDVREC");
  141.             else
  142.             {
  143.                 if ( load_form(),selected() )
  144.                 {
  145.                     show_form();
  146.                     for ( j = 0,i = ISAM_field_range; j < 5; i++ )
  147.                     {
  148.                         q = strdup( *(burlap[i].fptr) );
  149.                         strip_blanks( q );
  150.                         if ( strlen(q) )
  151.                         {
  152.                             prt_label_line( q );
  153.                             j++;
  154.                         }
  155.                         free (q);
  156.                     }
  157.                     for ( ; j < 6; j++ )
  158.                     {
  159.                         fputc( '\r', stdprn );
  160.                         fputc( '\n', stdprn );
  161.                     }
  162.                     fflush( stdprn );
  163.                 }
  164.             }
  165.         }}
  166.     }
  167. }
  168.  
  169.